rm(list = ls())
library(tidyverse)
library(estimatr)
library(grid)
library(ri2)
library(reshape2)
library(bandit)
library(stargazer)
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
set.seed(10027)
source('fn.R')

load('data.rdata')

mod <- lm_robust(Y ~ arm - 1, data = data, weights = ipw)
true <- coef(mod)

iter  <- 10000
if (file.exists('Output/TF1_simulation.rdata')){
  load('Output/TF1_simulation.rdata')
}else {
  out_h <- simulate_hybrid(periods = 1, n = 1000, probs = true, iter = iter, ntop = 5)
}

hybrid <- result_hybrid(data = as.data.frame(out_h$d_fit), iter = iter)
final  <- hybrid %>% dplyr::select(term, true, best, top5, rmse, coverage)
names(final) <- c('Arm', 'True', '% Best', '% Top 5', 'RMSE', 'Coverage')
stargazer::stargazer(final, rownames = F, summary = F, digits = 3)
